package com.powerhua.core.utils;

/**
 * 
 * @author brian
 *
 */
public class PathUtils {

    /**
     * class base path
     * 
     * @return
     */
    public static String getClassBasePath() {
        //String fileSeparator = System.getProperty("file.separator");
        String clazzStr = "PathUtils.class";
        Class<PathUtils> clazz = PathUtils.class;

        // full class path
        String fullClassPath = clazz.getResource(clazzStr).getPath();

        // package string
        String packageName = clazz.getPackage().getName();

        // package and class string
        int classLength = packageName.length() + clazzStr.length() + 1;

        // 
        int cutLength = fullClassPath.length() - classLength;
        String baseClassPath = fullClassPath.substring(0, cutLength);
        
        if(baseClassPath.indexOf("file:") == 0) {
            int len = baseClassPath.length();
            baseClassPath = baseClassPath.substring(5, len);
        }

        // return
        return baseClassPath;
    }

    /**
     * 测试用
     * @param args
     */
    public static void main(String[] args) {
        System.out.println("class base path: " + getClassBasePath());
    }
}
